package com.trkj.service.wxy;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.wxy.AuxiliaryInformationDao;
import com.trkj.dao.wxy.SkillDao;
import com.trkj.pojo.AuxiliaryInformation;
import com.trkj.pojo.Skill;
import com.trkj.service.ServiceException;
import com.trkj.vo.wxy.AuxiliaryInformationPageVo;



@Service
@Transactional(rollbackFor = Exception.class)
public class AuxiliaryInformationService {
	@Autowired
	private AuxiliaryInformationDao auxiliaryInformationDao;
	@Autowired
	private SkillDao skillDao;
	/**
	 * 查询所有的记录
	 */
	public List<AuxiliaryInformationPageVo> queryByAssistDataPage(int page,int rows) throws ServiceException{
		try {
			List<Object[]> list = auxiliaryInformationDao.queryByExamAssistData(new PageRequest(page-1, rows));
			
			List<AuxiliaryInformationPageVo> listAuxiInforPageVo = new ArrayList<>();
			if(list != null){
				for (Object[] objs : list) {
					AuxiliaryInformation a = (AuxiliaryInformation) objs[0];
					Skill s = (Skill) objs[1];
					
					AuxiliaryInformationPageVo auxiliaryInformationPageVo = new AuxiliaryInformationPageVo();
					auxiliaryInformationPageVo.setCodingId(a.getCodingId());
					auxiliaryInformationPageVo.setCodingName(a.getCodingName());
					auxiliaryInformationPageVo.setCodingBlockup(a.getCodingBlockup());
					auxiliaryInformationPageVo.setCodingFinaylly(a.getCodingFinaylly());
					auxiliaryInformationPageVo.setCodingPerson(a.getCodingPerson());
					auxiliaryInformationPageVo.setCodingRemark(a.getCodingRemark());
					auxiliaryInformationPageVo.setCodingUpdate(a.getCodingUpdate());
					auxiliaryInformationPageVo.setSkillName(s.getSkillName());
					
					listAuxiInforPageVo.add(auxiliaryInformationPageVo);
				}
			}
			return listAuxiInforPageVo;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 获取总记录数
	 * @return
	 */
	public long empByPageCount(){
		return auxiliaryInformationDao.count();
		
	}
		
	/**
	 * 新增
	 * @return
	 * @throws ServiceException 
	 */
	public void questionBank_insert(String codingName,String skillName,String codingRemark,BigDecimal codingBlockup) throws ServiceException{
		try {
			AuxiliaryInformation auInformation = new AuxiliaryInformation();
			Skill skill = skillDao.queryByDefinitionDeptName(skillName);
			auInformation.setCodingName(codingName);			
			auInformation.setCodingRemark(codingRemark);
			auInformation.setCodingBlockup(codingBlockup);
			auInformation.setCodingUpdate(new Timestamp(new Date().getTime()));
			auInformation.setCodingFinaylly(new Timestamp(new Date().getTime()));
			auInformation.setSkill(skill);
			System.out.println(auInformation.getCodingName()+"11"+auInformation.getCodingBlockup());
			auxiliaryInformationDao.save(auInformation);
			 
		
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
			
		}
	}
	
	
	/**
	 * 删除
	 * @param upId
	 * @throws ServiceException
	 */
	public void AuxiLiary_delete(Long codingId) throws ServiceException{
		try {
			auxiliaryInformationDao.delete(codingId);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new ServiceException(e);
		}
		
	}
	
	
	/**
	 * 查询所有的记录技能
	 */
	public List<Skill> findAll_skillName(){
		return (List<Skill>) skillDao.findAll();
	}

}
